<template>
    <div>
        <el-dialog
            width="400px"
            :visible.sync="is_show"
            title="更新订单状态"
            center
            @closed="closed"
        >
            <el-form
                ref="form"
                :model="form"
                :rules="rules"
            >
                <el-form-item
                    label="状态"
                    prop="status"
                >
                    <el-select
                        placeholder="请选择流程状态"
                        v-model="form.status"
                    >
                        <el-option label="已提交" value="已提交"></el-option>
                        <el-option label="已下证" value="已下证"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <template slot="footer">
                <el-button @click="is_show = false">取消</el-button>
                <el-button type="primary" @click="submit" v-no-more-click:3000>确定</el-button>
            </template>
        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            is_show: false,
            form: {
                status: '',
            },
            rules: {
                status:[
                    { required: true, message: '请输入流程状态', trigger: 'blur' },
                ],
            },
            order_id: null
        }
    },
    methods: {
        showOn(id) {
            this.order_id = id
            this.is_show = true
            this.$nextTick(() => {
                this.$refs['form'].clearValidate()
            })
        },
        submit() {
            this.$refs['form'].validate(valid => {
                if (valid) {
                    this.$axios.put(`/api/software/${this.order_id}/update`, this.form).then(res => {
                        if (res.data.code == 200) {
                            this.$emit('refresh')
                            this.$message({
                                type: 'success',
                                message: '修改成功'
                            })
                            this.is_show = false
                        } else {
                            this.$message({
                                type: 'error',
                                message: res.data.message
                            })
                        }
                    }).catch(e => {
                        console.log(e)
                    })
                }
            })
        },
        closed() {
			Object.assign(this.$data, this.$options.data())
            this.$refs['form'].resetFields()
        }
    }
}
</script>

<style lang="less" scoped>
/deep/.el-select {
    width: 100%;
}
</style>
